<%= render :partial => "/tr8n/admin/common/header" %>
<%= render :partial => "tabs", :locals => {:current_tab => "Translator: #{@translator.name}"} %>

<table class="admin_table">
    <tr>
        <th>
            Translator Id
        </th>
        <td>
            <%=@translator.id %>
        </td>
    </tr>
    <tr>
        <th width="160">
            User
        </th>
        <td>
          <% if @translator.user %>
            <%=link_to(@translator.name, @translator.link) %>
            (id: <%=@translator.user.id%>, email: <%=@translator.email%>)
          <% else %>
            Unknown  
          <% end %>  
        </td>
    </tr>
    <tr>
        <th>
            Access Code
        </th>
        <td>
            <%= @translator.access_key %>
            (<%= link_to('generate', {:action => :generate_access_key, :translator_id => @translator.id}, {:confirm => "Are you sure you want to generate translator access key?"}) %>)
            <span style="color: #888">Used to access restricted components when user is logged out.</span>
        </td>
    </tr> 
    <tr>
        <th>
            Site Administrator
        </th>
        <td>
            <%= @translator.admin? %>
        </td>
    </tr>
    <tr>
        <th>
            Translator Level
        </th>
        <td>
            <span id="translator_level_container"> 
              <span id='translator_title'><%= @translator.title %> (<%= @translator.level %>)</span>
              &nbsp;&nbsp;
              <%= link_to_function('change', "Tr8n.Effects.hide('translator_level_container'); Tr8n.Effects.show('translator_level_options_container');") unless @translator.admin? %>
            </span>
            
            <span id="translator_level_options_container" style='display:none'>
            	<% form_tag do %>
	              <%= select_tag('translator_level', options_for_select(Tr8n::Translator.level_options, @translator.level.to_s)) %>
	              <%= link_to_function('save', 'updateTranslatorLevel()')%> | <%= link_to_function('cancel', "Tr8n.Effects.show('translator_level_container'); Tr8n.Effects.hide('translator_level_options_container');")%>
							<% end %>
            </span>
            
        </td>
    </tr> 
    <tr>
        <th>
            Blocked
        </th>
        <td>
            <%=@translator.blocked? %>
        </td>
    </tr>
		<tr>
        <th>
            Rank
        </th>
        <td>
            <%= (@translator.rank ? (@translator.rank * 100).to_i / 100.0 : 0) %>
        </td>
		</tr>	
    <tr>
        <th>
            Last Ip
        </th>
        <td>
            <%= @translator.last_ip %>
        </td>
    </tr> 
    <tr>
        <th>
            Country Code
        </th>
        <td>
            <%= @translator.country_code %>
        </td>
    </tr> 
    <tr>
        <th>
            Inline Translations Enabled
        </th>
        <td>
            <%=@translator.enable_inline_translations? %>
        </td>
    </tr>
    <tr>
        <th>
            Translations Count
        </th>
        <td>
            <%=@translator.total_metric.total_translations %>
        </td>
    </tr>
    <tr>
        <th>
            Votes Count
        </th>
        <td>
          <%=@translator.total_metric.total_votes || 0 %>
          (<span style="color:green"><%=@translator.total_metric.positive_votes || 0 %></span>/<span style="color:red"><%=@translator.total_metric.negative_votes || 0 %></span>)
        </td>
    </tr>
     <tr>
        <th>
            Created At
        </th>
        <td>
            <%=@translator.created_at %>
        </td>
    </tr>    
    <tr>
        <th>
            Updated At
        </th>
        <td>
            <%=@translator.updated_at %>
        </td>
    </tr>
    <tr>
        <th>
            
        </th>
        <td>
          <% if @translator.blocked? %>
            <%=link_to_function("Unblock", "performTranslatorAction('unblock')") %>
          <% else %>
            <%=link_to_function("Block", "performTranslatorAction('block')") %>
          <% end %>  

          | <%=link_to("Delete", {:action => :delete, :translator_id => @translator.id}, :confirm => "Are you sure you want to do that?")%>
					
        </td>
    </tr>    
</table>

<script>
  function performTranslatorAction(action) {
    var reason = prompt("Please provide a reason why you want to " + action + " this translator:");
    location = "/tr8n/admin/translator/" + action + "?translator_id=<%=@translator.id%>&reason=" + reason;
  }  
</script>


<%=  tr8n_sections_tag(:modes => [
            ["Activity",    {:mode => :activity}],
            ["Applications", {:mode => :applications}],
            ["Assignments", {:mode => :assignments}],
            ["Metrics",     {:mode => :metrics}],
            ["Languages",   {:mode => :languages}],
            ["Translations",   {:mode => :translations}],
            ["Votes",   {:mode => :votes}],
            ["Locks",   {:mode => :locks}],
            ["Following",   {:mode => :following}],
            ["Forum Messages",   {:mode => :messages}],
            ["Reports",   {:mode => :reports}],
        ],
        :params => {
            :id => @translator.id
        }
) %>

<%= render :partial => "/tr8n/admin/common/footer" %>

<script>
	function updateTranslatorLevel() {
		var reason = prompt("Please provide the reason for promoting/demoting this translator:");
		if (reason) reason = "";
		location = "/tr8n/admin/translator/update_level?translator_id=<%=@translator.id%>&new_level=" + Tr8n.value('translator_level') + "&reason=" + reason;
	}
</script>
